// pages/oa/approval/myoalist.js
var api = require("../../../utils/api.js");
var util = require('../../../utils/util.js');
var orgid = "";
var userId = "";
var pagetitle = ["业务审批", "用印审批", "财务审批", "人事审批", "行政审批"];
var examineType = "";
var pageNum = 0;
var pageSize = 10;//每页显示条数
var hasMoreData = true;
var isExamine = "";
var sendUserId = "";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    examineTypeList: ["用印申请", "发票申请", "费用减免申请", "退费申请", "结案申请", "接案审批"],
    searchName: "",
    myCopyOaApplyList: [],
    companyName: wx.getStorageSync('companyName'),//律所名字

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var titleid = options.id;
    pageNum = 0;
    userId = wx.getStorageSync('userId');
    orgid = wx.getStorageSync('companyId');
    isExamine = options.isExamine;
    sendUserId = options.sendUserId;
    examineType = titleid;
    var that = this;
    wx.setNavigationBarTitle({
      title: pagetitle[titleid]
    });

    that.myCopyOaApplyList();
  },

  myCopyOaApplyList: function () {
    var that = this;
    wx.showLoading({
    });
    api.fetchApi2("myOaApply/myCopyOaApplyList", {
      orgid: orgid,
      userId: userId,
      examineType: examineType,
      searchName: that.data.searchName,
      pageNum: pageNum,
      pageSize: pageSize,
      isExamine: isExamine,
      sendUserId: sendUserId,
    }, "POST").then(res => {
      wx.hideLoading();
      if (pageNum == 0) {
        var list = res.data.oaProcessApprovalList;
      } else {
        var list = that.data.myCopyOaApplyList.concat(res.data.oaProcessApprovalList);
      }
      for (var i = 0; i < list.length; i++) {
        var finalState = list[i].is_examine;
        if (finalState == "2") {
          list[i].is_examine = "审批中";
        } else if (finalState == "1") {
          list[i].is_examine = "已拒绝";
        } else if (finalState == "0") {
          list[i].is_examine = "已通过";
        }

        // 处理时间
        var create_time = list[i].create_time;
        create_time = util.formatTimeTT(create_time, "Y-M-D");
        list[i].oa_create_time = create_time;
      }

      if (res.data.oaProcessApprovalList.length >= pageSize) {
        var num = pageNum + pageSize;
        hasMoreData = true;
        pageNum = num;

      } else {
        hasMoreData = false;
      }
      that.setData({
        myCopyOaApplyList: list
      })
    });

  },
  //模糊查询申请信息
  searchCaseList: function (e) {
    var that = this;
    pageNum = 0;
    pageSize = 10;
    that.setData({
      searchName: e.detail.value
    })
    that.myCopyOaApplyList();

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    //案件收支加載更多
    if (hasMoreData) {
      that.myCopyOaApplyList()
    } else {
      wx.showToast({
        title: '没有更多数据',
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  showdetail: function (e) {
    var caseId = e.currentTarget.dataset.caseid;
    var oaId = e.currentTarget.dataset.oaid;
    wx.navigateTo({
      url: 'myoadetails?caseId=' + caseId + "&oaId=" + oaId
    });
  },


})